package com.immac.leejc.randomaccess;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomAccessProcess {
	RandomAccessFile randomAccessFile;
	
	public RandomAccessProcess(String pathName, String mode) throws FileNotFoundException {
		File file = new File(pathName);
		randomAccessFile = new RandomAccessFile(file, mode);
	}

	public void close() throws IOException {
		randomAccessFile.close();
	}
	
	public void write(int offset, byte b) throws InterruptedException, IOException {
		randomAccessFile.seek(offset);
		randomAccessFile.write(b);
	}

	public byte readByte(int offset) throws IOException {
		randomAccessFile.seek(offset);
		return randomAccessFile.readByte();
	}
	
	public void write(int offset, int i) throws InterruptedException, IOException {
		randomAccessFile.seek(offset);
		randomAccessFile.write(i);
	}

	public int readint(int offset) throws IOException {
		randomAccessFile.seek(offset);
		return randomAccessFile.readInt();
	}
}
